<?php
$sub_menu = "230240";
include_once("_common.php");

auth_check($auth[$sub_menu], "r");

$token = get_token();

//$qstr .= "&fr_date=$fr_date&to_date=$to_date&date=$date&rel_table=$rel_table&rel_id=$rel_id";

if (!is_numeric($page)) $page = 1;
if (!$sfl) $sfl = 'mb_id';
if (!$cond_comp) $cond_comp = 'more';

$sql_common = " from $g4[member_table] m, $mw_cash[cash_table] c ";
$sql_search = " where  m.mb_id = c.mb_id ";

if ($stx) {
    $sql_search .= " and ( ";
    switch ($sfl) {
        case "mb_id" :
            $sql_search .= " (m.mb_id = '$stx') ";
            break;
        default : 
            $sql_search .= " ($sfl like '%$stx%') ";
            break;
    }
    $sql_search .= " ) ";
}

if ($cond and $cond_val and $cond_comp)
{
    $comp = '>';
    if ($cond_comp == 'more') $comp = '>';
    if ($cond_comp == 'below') $comp = '<';

    if ($cond == 'mb_point') $sql_search .= " and m.mb_point $comp $cond_val ";
    if ($cond == 'mb_cash') $sql_search .= " and c.mb_cash $comp $cond_val ";
}

if (!$sst) {
    $sst  = "mb_datetime";
    $sod = "desc";
}
$sql_order = " order by $sst $sod ";

$sql = "select count(*) as cnt
        $sql_common
        $sql_search";
$row = sql_fetch($sql);
$total_count = $row[cnt];

$rows = $config[cf_page_rows];
$total_page  = ceil($total_count / $rows);  // 전체 페이지 계산
if ($page == "") { $page = 1; } // 페이지가 없으면 첫 페이지 (1 페이지)
$from_record = ($page - 1) * $rows; // 시작 열을 구함  */

$sql = "select *
        $sql_common
        $sql_search
        $sql_order
        limit $from_record, $rows ";
$result = sql_query($sql);

$query_string = "cond=$cond&cond_val=$cond_val&cond_comp=$cond_comp";
$write_pages = get_paging($rows, $page, $total_page, "$PHP_SELF?{$qstr}&{$query_string}&page=");

$listall = "<a href='$_SERVER[PHP_SELF]'>처음</a>";

$g4[title] = "캐쉬사용내역";
include_once ("$g4[admin_path]/admin.head.php");

$colspan = 8;
?>

<script type="text/javascript" src="<?=$g4[path]?>/js/sideview.js"></script>

<table width=100%>
<form name=fsearch method=get>
<tr>
    <td width=30% align=left>
        <?=$listall?> (건수 : <?=number_format($total_count)?>)
    </td>
    <td width=70% align=right>
        <select name="cond">
            <option value=''>조건검색</option>
            <option value='mb_point'>포인트</option>
            <option value='mb_cash'><?=$mw_cash[cf_cash_name]?></option>
        </select>

        <input type="text" class="ed" size="5" numeric name="cond_val" value="<?=$cond_val?>"/>
        
        <select name="cond_comp">
            <option value='more'>이상</option>
            <option value='below'>이하</option>
        </select>
 
        <select name=sfl class=cssfl>
            <option value='mb_id'>회원아이디</option>
            <option value='mb_name'>회원이름</option>
            <option value='mb_nick'>회원별명</option>
        </select>
        <input type=text name=stx class=ed itemname='검색어' value='<?=$stx?>'>
        <input type=image src='<?=$g4[admin_path]?>/img/btn_search.gif' align=absmiddle></td>

        <script type="text/javascript">
        document.fsearch.sfl.value = '<?=$sfl?>';
        document.fsearch.cond.value = '<?=$cond?>';
        document.fsearch.cond_comp.value = '<?=$cond_comp?>';
        </script>
</tr>
</form>
</table>

<form name=fpointlist method=post>
<input type=hidden name=sst   value='<?=$sst?>'>
<input type=hidden name=sod   value='<?=$sod?>'>
<input type=hidden name=sfl   value='<?=$sfl?>'>
<input type=hidden name=stx   value='<?=$stx?>'>
<input type=hidden name=page  value='<?=$page?>'>
<input type=hidden name=token value='<?=$token?>'>

<table width=100% cellpadding=0 cellspacing=1>
<colgroup width=''>
<!--<colgroup width=120>-->
<colgroup width=120>
<colgroup width=120>
<colgroup width=120>
<colgroup width=100>
<colgroup width=100>
<tr><td colspan='<?=$colspan?>' class='line1'></td></tr>
<tr class='bgcol1 bold col1 ht center'>
    <td>별명</td>
    <!--<td><?//=subject_sort_link('m.mb_id', $query_string)?>회원ID</a></td>-->
    <td><?=subject_sort_link('mb_point', $query_string)?>포인트</a></td>
    <td>가용포인트</a></td>
    <td><?=subject_sort_link('mb_cash', $query_string)?><?=$mw_cash[cf_cash_name]?></a></td>
    <td><?=subject_sort_link('mb_datetime', $query_string)?>가입일</a></td>
    <td><?=subject_sort_link('mb_today_login', $query_string)?>최근로그인</a></td>
</tr>
<tr><td colspan='<?=$colspan?>' class='line2'></td></tr>
<?
for ($i=0; $row=sql_fetch_array($result); $i++) 
{
    $mb_nick = get_sideview($row[mb_id], $row[mb_nick], $row[mb_email], $row[mb_homepage]);

    $list = $i%2;
    echo "
    <input type=hidden name=cl_id[$i] value='$row[cl_id]'>
    <tr class='list$list col1 ht center'>
        <td>$mb_nick</td>
        <!--<td><a href='$g4[admin_path]/point_list.php?sfl=mb_id&stx=$row[mb_id]'>$row[mb_id]</a></td>-->
        <td><a href='$g4[admin_path]/point_list.php?sfl=mb_id&stx=$row[mb_id]'>".number_format($row[mb_point])."</a></td>
        <td>".number_format(mw_get_point_to_cash_possible($row[mb_id]))."</td>
        <td><a href='$g4[admin_path]/mw.cash/mw.cash.list.php?sfl=mb_id&stx=$row[mb_id]'>"
            .number_format($row[mb_cash])." $mw_cash[cf_cash_unit]</a></td>
        <td>".substr($row[mb_datetime], 0, 10)."</td>
        <td>".substr($row[mb_today_login], 0, 10)."</td>
    </tr> ";
} 

if ($i == 0)
    echo "<tr><td colspan='$colspan' align=center height=100 bgcolor=#ffffff>자료가 없습니다.</td></tr>";

echo "<tr><td colspan='$colspan' class='line2'></td></tr>";
echo "</table>";

echo "<table width=100% cellpadding=3 cellspacing=1>";
echo "<tr><td width=50%>";
echo "</td>";
echo "<td width=50% align=right>$write_pages</td></tr></table>\n";

if (strstr($sfl, "mb_id"))
    $mb_id = $stx;
else
    $mb_id = "";
?>
</form>

<script type="text/javascript"> document.fsearch.stx.focus(); </script>

<?
include_once ("$g4[admin_path]/admin.tail.php");
